﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using ExtAspNet;


namespace TCMSystem.admin
{
    public partial class config : PageBase
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        #region Module

        /// <summary>
        /// 当前页面所属的模块
        /// </summary>
        public override ModuleType Module
        {
            get
            {
                return ModuleType.CoreConf;
            }
        }

        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            // 权限检查
            CheckPowerEditWithButton(btnSave);


            tbxTitle.Text = TblMstConfigHelper.Title;
            nbxPageSize.Text = TblMstConfigHelper.PageSize.ToString();
            //ddlMenuType.SelectedValue = TblMstConfigHelper.MenuType.ToLower();
            tbxHelpList.Text = ScriptUtil.GetJSBeautifyString(TblMstConfigHelper.HelpList);
        }

        #endregion

        #region Events

        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            // 在操作之前进行权限检查
            if (!CheckPowerEdit())
            {
                CheckPowerFailWithAlert();
                return;
            }

            string helpListStr = tbxHelpList.Text.Trim();
            try
            {
                //new Nii.JSON.JSONArray(helpListStr);
                JArray.Parse(helpListStr);
            }
            catch (Exception)
            {
                tbxHelpList.MarkInvalid("格式不正确，必须是JSON字符串！");

                return;
            }



            TblMstConfigHelper.Title = tbxTitle.Text.Trim();
            TblMstConfigHelper.PageSize = Convert.ToInt32(nbxPageSize.Text.Trim());
            //if (TblMstConfigHelper.MenuType != ddlMenuType.SelectedValue.ToLower())
            //{
            //    TblMstConfigHelper.MenuType = ddlMenuType.SelectedValue.ToLower();
            //    menuTypeChanged = true;
            //}
            TblMstConfigHelper.HelpList = helpListStr;
            TblMstConfigHelper.SaveAll();

            Alert.ShowInParent("修改系统配置成功！");

        }

        #endregion
    }
}
